<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="仓库名称" prop="name">
        <el-input v-model="dataForm.name" placeholder="名称:剑南仓"></el-input>
      </el-form-item>
      <el-form-item label="仓库地址" prop="address">
        <el-input v-model="dataForm.address" placeholder="地址:四川成都"></el-input>
      </el-form-item>
      <el-form-item label="仓库编码" prop="areaCode">
        <el-input v-model="dataForm.areaCode" placeholder="编码:SC-001"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {}
      }
    },
    methods: {
      init (id) {
        this.visible = true
        if (id !== undefined) {
          this.$http({
            url: this.$http.adornUrl(`/mall-product/product/house/detail/${id}`),
            method: 'get'
          }).then(({data}) => {
            this.dataForm = data.data
          })
        }
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl('/mall-product/product/house/saveOrUpdateHouse'),
              method: 'post',
              data: this.dataForm
            }).then(({data}) => {
              if (data.data === true && data.code === 200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message({
                  showClose: true,
                  message: data.message,
                  type: 'warning',
                  center: true
                })
              }
            })
          }
        })
      }
    }
  }
</script>
<style>
#dialog{
  width: 50%;
  height: 65%;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
}
</style>